// 登录界面切换
$(function () {
    $(".PASS-login").css({
        color: "#005aaa",
        borderBottom: "2px solid #005aaa",
    })
    $(".login-user div").click(function () {
        $(this).css({
            color: "#005aaa",
            borderBottom: "2px solid #005aaa",
        }).siblings().css({
            color: "",
            borderBottom: ""
        })
    })
})

let oPassLogin = document.querySelector(".PASS-login");
let oSmsLogin = document.querySelector(".SMS-login");
let firstPass = document.querySelector("#passLogin");
let lastSms = document.querySelector("#smsLogin");

oSmsLogin.onclick = function () {
    firstPass.style.display = "none";
    lastSms.style.display = "block";
}

oPassLogin.onclick = function () {
    firstPass.style.display = "block";
    lastSms.style.display = "none";
}

//二维码


//登录用户名
let oPhone = document.querySelector(".iphone");
let oUser = document.querySelector("#user");
let oPas = document.querySelector("#pas");
let oPassword = document.querySelector(".password");
let oCheck = document.querySelectorAll(".checkBox")[0];

oUser.onfocus = function () {
    oPhone.style.borderBottom = "1px solid #005aaa";
}

oUser.onblur = function () {
    oPhone.style.borderBottom = "";
}

oPas.onfocus = function () {
    oPassword.style.borderBottom = "1px solid #005aaa";
}

oPas.onblur = function () {
    oPassword.style.borderBottom = "";
}

//登录按钮实现用户名和密码
$(function () {
    $(".loginBtn").click(function () {
        if (oUser.value == "") {
            alert("请填写用户名");
        } else if (oPas.value == "") {
            alert("请填写密码");
        } else if (oCheck.checked == false) {
            alert("请阅读服务条款")
        }
        //跳转
    })
})

//登录和免登录
$(function () {
    $(".loginBtn").click(function () {
        $.post(
            "goodsAndShoppingCart/login.php", {
                "username": $("#user").val(),
                "userpass": $("#pas").val()
            },
            function (data) {
                if (data == "success") {
                    // $("#messageBox").html("亲，恭喜您，登录成功！2秒后跳转到<a href='index.html'>首页</a>");
                    //保存cookie：
                    saveCookie("username", $("#user").val(), 14);
                    setTimeout(() => {
                        location.href = "index.html";
                    }, 2000);
                } else if (data == "fail") {
                    $("#messageBox").html("不好意思，亲，用户名或者密码错误！");
                } else {
                    $("#messageBox").html("不好意思，亲，服务器出错了！");
                }
            }
        );
    });
});